ns = 'arm-daliy-product-reporter!';
// 初始化函数
function showAddDialog(){
	window.showModalDialog("../../reporter/daily/select-product",window);
}
function addDataLine(hostCode,hostName,actionValue,passedValue,wasterValue,testValue,remark,itemType) {
	itemIndex++;
	var armPrefix = "bean.armItems[" + itemIndex + "].";
	var datas = [ {
		"type" : "text",
		"attrs" : {
			"name" : armPrefix + "host.code",
			"value":hostCode,
			"readOnly":true
		},
		"className":"code-field"
	}, {
		"type" : "text",
		"attrs" : {
			"name" : armPrefix + "host.name",
			"value":hostName,
			"readOnly" : true
		},
		"className":"code-field"
	},
	// 年期初结存
	{
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	},
	// 月起初结存
	{
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	},
	// 月计划
	{
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	},
	// 当月动工
	{
		"type" : "text",
		"attrs" : {
			"name" : fieldValueName("Action", itemIndex,"atomValue"),
			"value" : actionValue
		},
		"events" : {
			"blur" : function() {
				return judgeNumber(this);
			}
		},
		"className":"number-field"
			
	}, {
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	} ,
	
	// 合格
	{
		"type" : "text",
		"attrs" : {
			"name" : fieldValueName("Passed", itemIndex,"atomValue"),
			"value" : passedValue
		},
		"events" : {
			"blur" : function() {
				return judgeNumber(this);
			}
		},
		"className":"number-field"
	}, {
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	} ,
	// 废品
	{
		"type" : "text",
		"attrs" : {
			"name" : fieldValueName("Waster", itemIndex,"atomValue"),
			"value" : wasterValue
			
		},
		"events" : {
			"blur" : function() {
				return judgeNumber(this);
			}
		},
		"className":"number-field"
	}, {
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	} ,
	// 试销
	{
		"type" : "text",
		"attrs" : {
			"name" : fieldValueName("Test", itemIndex,"atomValue"),
			"value" : testValue
		},
		"events" : {
			"blur" : function() {
				return judgeNumber(this);
			}
		},
	    "className":"number-field"
	}, {
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	} ,

	
	
	// 期末结存
	{
		"type" : "label",
		"attrs" : {
			"text" : 0
		}
	},

	// 备注
	{
		"type" : "text",
		"attrs" : {
			"name" : armPrefix + "remark",
			"value":remark,
			"title":remark
		},
		"className":"number-field remarkTip"
	}, {
		"type" : "text",
		"attrs" : {
			"name" : armPrefix + "itemType",
			"value" : itemType,
			"readOnly" : true
			
		},
	    "className":"number-field"

	}, {
		"type" : "img",
		"attrs" : {
			"src" : sbase + "/images/removeme.gif"
		},
		"csses" : {
			"cursor" : "hand"
		},
		"events" : {
			"click" : function() {
				$(this).parent().parent().remove();
			}
		}
	}

	];
	addDataItem(datas, pdtBody);
	
}

var results = [];
var curidx=0;
function search(){
	var key = $("#scode").val();
	if(key=='')return;
	results = $("#pdtBody tr").filter(function(idx){
		$(this).removeClass('info');
		var code = $("td:nth-child(1) :text",this).val();
		if(code==undefined){
			return false;
		}else{
			return ~code.indexOf(key);	
		}
		
		//return ~code.indexOf(key);
	});	
	$.each(results,function(idx,item){
		$(item).addClass('info');		
	});
	goNext();

}
function goNext(){
	if(curidx>=results.length){
		alert('已经到了最后一个');
		return;
	}
	var psn = $(results[curidx++]).position();
	$(document).scrollTop(psn.top);
}